package theOrbalEra.common.block;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class ContainerOrballFactory extends Container{
	@Override
	public void putStackInSlot(int par1, ItemStack par2ItemStack) {
		if(par1==0)
			for(int i=1;i<7;i++)
				super.putStackInSlot(i, null);
		super.putStackInSlot(par1, par2ItemStack);
	}


	public ContainerOrballFactory(InventoryPlayer par1InventoryPlayer, TileEntityOrballFactory par2TileEntityGloriousFactory){
		this.addSlotToContainer(new Slot(par2TileEntityGloriousFactory, 0, 78, 144));
		this.addSlotToContainer(new SlotOrballFac(par2TileEntityGloriousFactory, 1, 78, 72));
		this.addSlotToContainer(new SlotOrballFac(par2TileEntityGloriousFactory, 2, 26, 101));
		this.addSlotToContainer(new SlotOrballFac(par2TileEntityGloriousFactory, 3, 26, 39));
		this.addSlotToContainer(new SlotOrballFac(par2TileEntityGloriousFactory, 4, 78, 10));
		this.addSlotToContainer(new SlotOrballFac(par2TileEntityGloriousFactory, 5, 130, 102));
		this.addSlotToContainer(new SlotOrballFac(par2TileEntityGloriousFactory, 6, 130, 39));
		
		
        int var1;
        
                
            
        
        for (var1 = 0; var1 < 3; ++var1)
        {
            for (int var2 = 0; var2 < 9; ++var2)
            {
                this.addSlotToContainer(new Slot(par1InventoryPlayer, var2 + var1 * 9+9, 8 + var2 * 18, 174 + var1 * 18));
            }
        }
        
       

        for (var1 = 0; var1 < 9; ++var1)
        {
            this.addSlotToContainer(new Slot(par1InventoryPlayer, var1, 8 + var1 * 18, 232));
        }
		
		 
        
	}
	
	@Override
    public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    {
		
	 ItemStack stack = null;
     Slot slotObject = (Slot) inventorySlots.get(par2);

     if (slotObject != null && slotObject.getHasStack()) {
             ItemStack stackInSlot = slotObject.getStack();
             stack = stackInSlot.copy();

             
             if (par2 == 6) {
                     if (!mergeItemStack(stackInSlot, 7,
                                     inventorySlots.size(), true)) {
                             return null;
                     }
             
             } else if (!mergeItemStack(stackInSlot, 0, 1, false)) {
                     return null;
             }

             if (stackInSlot.stackSize == 0) {
                     slotObject.putStack(null);
             } else {
                     slotObject.onSlotChanged();
             }
     }

     return stack;
    }
	@Override
	public boolean canInteractWith(EntityPlayer var1) {
		
		return true;
	}
	
	

}
